#include <Starflub/Starflub.h>

extern u32int placement_address;
extern fs_node_t *fs_root;

void SFInit(struct multiboot *mboot_ptr) {
	//Initialize Monitor
	monitor_clear();
	monitor_write_colored("Starflub ", LGREEN_COLOR);
	monitor_write_dec(SF_VERSION_MA);
	monitor_write(".");
	monitor_write_dec(SF_VERSION_MI);
	monitor_write("\r\n");
	monitor_write("\tWritten by ");
	monitor_write(SF_AUTHORS);
	monitor_write("\r\n\r\n");
	SFSysLog("Monitor initialized.\r\n");
	
	//Initialize descriptor table
	init_descriptor_tables();
	SFSysLog("GDT initialized.\r\n");
	SFSysLog("IDT initialized.\r\n");
	
	//Initialize the weird asm thing
	asm volatile("sti");
	SFSysLog("Interrupts enabled.\r\n");
	
	//Install keyboard
	kb_install();
	kb_disable();
	SFSysLog("Keyboard driver installed.\r\n");
	
	//Install mouse
	mouse_install();
	SFSysLog("Mouse driver installed.\r\n");
	
	//Find ramdisk
	ASSERT(mboot_ptr->mods_count > 0);
	u32int initrd_location = *((u32int*)mboot_ptr->mods_addr);
	u32int initrd_end = *(u32int*)(mboot_ptr->mods_addr+4);
	placement_address = initrd_end;
	SFSysLog("Ramdisk found.\r\n");
	
	//Start timer
//	init_timer(50);
//	SFSysLog("Mouse/Tasking timer initialized.\r\n");
	
	//Start paging
	initialize_paging();
	SFSysLog("Paging started.\r\n");
	
	//Start multitasking
	initialize_tasking();
	SFSysLog("Multitasking started.\r\n");
	
	//Init ramdisk, set as fs root
	fs_root = initialize_initrd(initrd_location);
	SFSysLog("Filesystem Root initialized.\r\n");
	
	//Start syscalls
//	initialize_syscalls();
//	SFSysLog("Syscalls initialized.\r\n");
	
	//Enter user mode
//	enterusermode();
//	SFSysLog("Entering user mode.");
	
	SFSysLog("Initialization complete.\r\n\r\n");
}

